class Solution(object):
    @classmethod
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        strLen = len(s)
        # 生成一个二维数组
        ans = [[0 for i in range(strLen)] for j in range(numRows)]
        strIndex = 0
        j = 0  # 横坐标
        while strIndex < strLen:
            for i in range(numRows):
                # 竖着的填内容
                if strIndex >= strLen:
                    break
                ans[i][j] = s[strIndex]
                strIndex += 1

            # 斜上方
            for i in range(numRows-2, 0, -1):
                j = j+1
                # 判断是否越界
                if strIndex >= strLen:
                    break
                ans[i][j] = s[strIndex]
                strIndex += 1

            j += 1

        s = ''
        for i in range(numRows):
            for j in range(strLen):
                if ans[i][j] != 0:
                    s += ans[i][j]
        # print(ans)
        return s


if __name__ == '__main__':
    ans = Solution()
    print(ans.convert('PAYPALISHIRING', 3))
